package com.ufcg.lvc.client.MyListGrids;

import java.util.List;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.ufcg.lvc.client.GreetingServiceCRUDAsync;
import com.ufcg.lvc.client.UserData;
import com.ufcg.lvc.client.Datas.TurmasData;

/**
 * 
 * @author Larissa Costa
 * 
 */
public class TurmasListGrid extends MyListGrid {
	UserData UD;
	public TurmasListGrid(GreetingServiceCRUDAsync servico, UserData uD) {
		super();
		UD= uD;
		String[] camposTurmas = { "nome", "disciplina", "instituicao", "ano" };
		String[] titulosTurmas = { "Nome", "Disciplina", "Instituição", "Ano" };

		this.setCampos(camposTurmas);
		this.setTitulos(titulosTurmas);
		this.setServico(servico);

		this.addColunas(campos, titulos);
		this.loadDados(UD);
	}

	public void loadDados(UserData uD) {
		UD = uD;

		final AsyncCallback<List<List<String>>> callback = new AsyncCallback<List<List<String>>>() {
			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Erro ao carregar turmas");
				System.out.println("Erro ao carregar turmas");
			}

			@Override
			public void onSuccess(List<List<String>> result) {
				setData(TurmasData.getRecords(result.get(0), result.get(1),result.get(2), result.get(3)));
			}
		};
		this.getServico().getTurmas(UD.getId_usuario(), callback);

	}
}